package com.lagou.mr.speak;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class SpeakReducer extends Reducer<Text, SpeakBean, Text, SpeakBean> {
    Text k = new Text();
    SpeakBean v = new SpeakBean();
    // 设备号
    private String deviceId;
    // 自有播放时长
    private long sum_self_duration;
    // 第三方播放时长
    private long sum_third_partDuration;

    @Override
    protected void reduce(Text k, Iterable<SpeakBean> values, Context context) throws IOException, InterruptedException {

        sum_self_duration = 0;
        sum_third_partDuration = 0;

        for (SpeakBean value : values) {
            sum_self_duration += value.getSelfDuration();
            sum_third_partDuration += value.getThirdPartDuration();
        }
        v.set(sum_self_duration, sum_third_partDuration);
        context.write(k ,v);
    }
}
